<template>
  <div class="home">
    <Header />
    <!-- 轮播图容器 -->
    <swiper
      :modules="modules"
      :slides-per-view="1"
      :space-between="30"
      :navigation="true"
      :pagination="{ clickable: true }"
      :autoplay="{
        delay: 5000,
        disableOnInteraction: false
      }"
    >
      <swiper-slide v-for="(product, index) in carouselProducts" :key="index">
        <img :src="product.image" alt="Product Image">
      </swiper-slide>
    </swiper>
    <div class="hero">
      <h1>欢迎来到我们的手机官网</h1>
      <p>这里有最新款的小米手机</p>
      <router-link to="/products" class="btn">查看产品</router-link>
    </div>
    <!-- 图片展示区域 -->
    <div class="showcase-container">
      <!-- 第一排图片 -->
      <div class="showcase-row">
        <div v-for="(item, index) in firstRowImages" :key="index" class="showcase-item">
          <img :src="item.image" :alt="item.title">
          <div class="showcase-content">
            <h3>{{ item.title }}</h3>
            <p>{{ item.description }}</p>
          </div>
        </div>
      </div>
      <!-- 第二排图片 -->
      <div class="showcase-row">
        <div v-for="(item, index) in secondRowImages" :key="index" class="showcase-item">
          <img :src="item.image" :alt="item.title">
          <div class="showcase-content">
            <h3>{{ item.title }}</h3>
            <p>{{ item.description }}</p>
          </div>
        </div>
      </div>
    </div>
    <Footer />
  </div>
</template>

<script setup>
// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from 'swiper/vue';

// Import Swiper styles
import 'swiper/css';
import 'swiper/css/autoplay';
import 'swiper/css/navigation';
import 'swiper/css/pagination';

// import required modules
import { Autoplay, Navigation, Pagination } from 'swiper';

import { ref } from 'vue';
import Footer from '../components/Footer.vue';
import Header from '../components/Header.vue';

// 轮播图数据
const carouselProducts = ref([
  { image: '/images/15pro.png' },
  { image: '/images/14pro.png' },
  { image: '/images/15pro.png' }
]);

// 第一排图片数据
const firstRowImages = ref([
  {
    title: '小米14 Pro',
    description: '徕卡光学全焦段四摄',
    image: '/images/15pro.png'
  },
  {
    title: '小米14',
    description: '徕卡双摄｜超窄边屏幕',
    image: '/images/14pro.png'
  },
  {
    title: 'Redmi K70 Pro',
    description: '2K 高光屏｜索尼IMX890',
    image: '/images/15pro.png'
  }
]);

// 第二排图片数据
const secondRowImages = ref([
  {
    title: 'Redmi K70',
    description: '1.5K 高光屏｜索尼IMX800',
    image: '/images/14pro.png'
  },
  {
    title: 'Redmi Note 13 Pro',
    description: '天玑7200-Ultra｜OLED直屏',
    image: '/images/15pro.png'
  },
  {
    title: '小米手机配件',
    description: '品质配件｜专业服务',
    image: '/images/14pro.png'
  }
]);

// 定义需要使用的 Swiper 模块
const modules = [Navigation, Pagination, Autoplay];
</script>

<style scoped>
.home {
  text-align: center;
  padding-top: 45px;
}

.hero {
  padding: 60px 0;
}

.btn {
  display: inline-block;
  background-color: #ff6700;
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 5px;
  transition: background-color 0.3s ease;
}

.btn:hover {
  background-color: #f85000;
}

/* 轮播图样式 */
.swiper {
  width: 100%;
  height: auto;
  position: relative;
  margin-top: 20px;
}

.swiper-slide {
  height: 650px;
  overflow: hidden;
}

.swiper-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 图片展示区域样式 */
.showcase-container {
  max-width: 1200px;
  margin: 0 auto 60px;
  padding: 0 20px;
}

.showcase-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.showcase-item {
  flex: 1;
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.showcase-item:hover {
  transform: translateY(-5px);
}

.showcase-item img {
  width: 100%;
  height: 250px;
  object-fit: cover;
}

.showcase-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  color: white;
  text-align: left;
}

.showcase-content h3 {
  margin: 0;
  font-size: 20px;
  font-weight: normal;
}

.showcase-content p {
  margin: 5px 0 0;
  font-size: 14px;
  opacity: 0.8;
}

/* 导航按钮样式 */
:deep(.swiper-button-next),
:deep(.swiper-button-prev) {
  color: rgba(255, 255, 255, 0.8);
  background-color: rgba(0, 0, 0, 0.2);
  padding: 25px;
  border-radius: 50%;
  width: 15px;
  height: 15px;
  transition: all 0.3s ease;
}

:deep(.swiper-button-next:hover),
:deep(.swiper-button-prev:hover) {
  background-color: rgba(0, 0, 0, 0.4);
  color: #ffffff;
}

/* 分页器样式 */
:deep(.swiper-pagination-bullet) {
  background: rgba(255, 255, 255, 0.6);
  opacity: 1;
}

:deep(.swiper-pagination-bullet-active) {
  background-color: rgba(255, 255, 255, 0.9);
}

@media (max-width: 768px) {
  .showcase-row {
    flex-direction: column;
  }

  .showcase-item {
    margin-bottom: 20px;
  }

  .showcase-item img {
    height: 200px;
  }
}
</style>
